<?php
Junction_FileCabinet::using("Junction_Core_Session");

/**
 * Factory which returns new sessions
 *
 * <p>The factory governs the construction of junction sessions.
 * Sessions can be costly to create as a result this class will
 * dole out new sessions sparingly.  It is preferably to reuse
 * a given session since it does not contain any mutable state.
 * 
 * @package junction.core
 */
class Junction_Core_SessionFactory
{
	/**
	 * Construct a new session given a class name.
	 * 
	 * <p>Manage the construction of sessions such that only one session is
	 * ever created for any given schema.  This ensures that sessions, which
	 * are expensive to create, do not get created needlessly when they can
	 * be shared.
	 *
	 * @param String $schema
	 * @return Junction_Core_Session
	 */
	public static function construct($schema) {
		static $mappings = array();
		if (!isset($mappings[$schema])) {
			$builder = new Junction_Core_Builder();
			$mappings[$schema] = new Junction_Core_Session($builder->build($schema));
		}
		return $mappings[$schema];
	}
}
?>
